package utils

import (
	"crypto/md5"
	"encoding/hex"
	"encoding/json"
	"log"
	"time"
)

type Result struct {
	Code      int    `json:"code"`
	Message   string `json:"message"`
	Url       string `json:"url"`
	Timestamp string `json:"timestamp"`
}

func JsonRes(code int, message string) string {
	r := Result{
		Code:      code,
		Message:   message,
		Timestamp: time.Now().Format("2006-01-02 15:04:05"),
	}
	j, err := json.Marshal(r)
	if err != nil {
		log.Println(err.Error())
	}
	return string(j)
}

func Md5Encode(s string) string {
	m := md5.New()
	m.Write([]byte(s))
	return hex.EncodeToString(m.Sum(nil))
}
